#include "serializer/io.h"
#include "serializer/serializer.h"

#include <gtest/gtest.h>

#include <string>
#include <tuple>

using namespace serializer;

/**
 * 验证 cpo.h 中的统一 CPO 接口与 streaming 读写器的协作
 * 涵盖: 基础类型、字符串、pair、tuple 等
 */
TEST(cpo_streaming_test, end_to_end_on_stream_like_io)
{
    vector_writer writer;
    default_options options{};

    // 序列化多个值（基础类型 + 复合类型）
    serialize(writer, 123, options);
    serialize(writer, std::string{"hello"}, options);
    serialize(writer, std::make_pair(1, std::string{"x"}), options);
    serialize(writer, std::tuple{2, std::string{"y"}}, options);

    // 反序列化应按相同顺序还原
    vector_reader reader(writer.data());
    auto v1 = deserialize<int>(reader, options);
    auto v2 = deserialize<std::string>(reader, options);
    auto v3 = deserialize<std::pair<int, std::string>>(reader, options);
    auto v4 = deserialize<std::tuple<int, std::string>>(reader, options);

    EXPECT_EQ(v1, 123);
    EXPECT_EQ(v2, std::string{"hello"});
    EXPECT_EQ(v3, (std::make_pair(1, std::string{"x"})));
    EXPECT_EQ(v4, (std::tuple<int, std::string>{2, std::string{"y"}}));
}
